package com.overoid.diary.ui;

import com.overoid.diary.R;

import com.overoid.diary.ui.common.ActivityImpl;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageButton;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import android.widget.AdapterView;
import android.widget.ViewSwitcher;

public class PictureActivity extends ActivityImpl implements AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory { 
    //KauiView m_View; 
	private ImageSwitcher mSwitcher; 

	@Override
	protected void onCreate(Bundle savedInstanceState) {
			
		super.onCreate(savedInstanceState);			
		
		setContentView(R.layout.picture);
		
		
		final ImageButton picImgBtnDone =  (ImageButton)findViewById(R.id.picImgBtnDone);
		picImgBtnDone.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//Toast.makeText(PictureActivity.this,"btn cancle",Toast.LENGTH_SHORT).show();
				Intent in = new Intent(PictureActivity.this,DayActivity.class);
				startActivity(in);	
				
			}
		});
		
		
		 
		
		 mSwitcher = (ImageSwitcher) findViewById(R.id.switcher); 
         mSwitcher.setFactory(this); 
         mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); 
         mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); 
  
         Gallery g = (Gallery) findViewById(R.id.gallery); 
         g.setAdapter(new ImageAdapter(this)); 
         g.setOnItemSelectedListener(this);  
         
         
	}
	 public void onNothingSelected(AdapterView parent) { 
     }  
	 
	 public void onItemSelected(AdapterView parent, View v, int position, long id) { 
		  
		 //mSwitcher.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
         mSwitcher.setImageResource(mImageIds[position]); 
         
     } 
	 
	 public View makeView() { 
         ImageView i = new ImageView(this);
         //i.setImageResource(R.drawable.icon);
         
         //i.layout_width
         //Log.d("===========================================",String.valueOf(i.getWidth()));
         i.setLayoutParams(new ImageSwitcher.LayoutParams(320,360));         
         i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
           
         return i; 
     } 
 
	 
	 public class ImageAdapter extends BaseAdapter { 
         public ImageAdapter(Context c) { 
             mContext = c; 
         } 
  
         public int getCount() { 
             return mThumbIds.length; 
         } 
  
         public Object getItem(int position) { 
             return position;
         } 
  
         public long getItemId(int position) { 
             return position; 
         } 
  
         public View getView(int position, View convertView, ViewGroup parent) { 
             ImageView i = new ImageView(mContext); 
  
             i.setImageResource(mThumbIds[position]); 
             i.setAdjustViewBounds(true); 
             i.setLayoutParams(new Gallery.LayoutParams(50, 50)); 
             //i.setBackgroundResource(R.drawable.picture_frame); 
             return i; 
         } 
  
         private Context mContext; 
  
     } 
	 
	 private Integer[] mThumbIds = {R.drawable.alram_52x52,R.drawable.alram_52x52,R.drawable.hiraita_480x420,R.drawable.ddd_ghdry125_rlagkstjd05};
			 //R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52}; 
  
     private Integer[] mImageIds ={R.drawable.alram_52x52,R.drawable.alram_52x52,R.drawable.hiraita_480x420 ,R.drawable.ddd_ghdry125_rlagkstjd05}; 
     //{R.drawable.alram_52x52,R.drawable.hiraita_480x420 , R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52,R.drawable.hiraita_480x420, R.drawable.alram_52x52}; 
 
 
}
